package com.library.bookmanagement.service.Impl;

import com.library.bookmanagement.entity.JwtUser;
import com.library.bookmanagement.entity.LoginUser;
import com.library.bookmanagement.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @author ：ZXM
 * @date ：Created in 2020/6/5 22:01
 * @description：实现UserDetailService类
 */
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private LoginService loginService;
    
    /**
    * @Description: 根据用户名获取登录用户信息
    * @Param: [s]
    * @return: org.springframework.security.core.userdetails.UserDetails
    * @Author: ZXM
    * @Date: 2020/6/10
    */
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        LoginUser loginUser = loginService.queryUserByName(s);
        return new JwtUser(loginUser);
    }
}
